@file:Suppress("unused")

package com.hjh.tool.extension

import com.drake.net.request.BodyRequest
import com.drake.net.request.MediaConst
import kotlinx.serialization.json.Json
import kotlinx.serialization.encodeToString
import okhttp3.RequestBody.Companion.toRequestBody

/**
 * @author： hjh
 * @createDate： 2024/12/7 15:15
 * @description：
 * @qq： 3472903821
 * @version: 1.0
 */
inline fun <reified T> BodyRequest.encodeJson(body: T) {
    this.body = Json.encodeToString(body).toRequestBody(MediaConst.JSON)
}

inline fun <reified T> encodeJson(body: T): String {
    return Json.encodeToString(body)
}

inline fun <reified T> decodeJson(text: String): T {
    return Json.decodeFromString(text)
}